import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import type {
  LoadingConfig,
  AdaptiveConfig,
  PaginationProps
} from "@pureadmin/table";
import { delay } from "@pureadmin/utils";
import { addDialog } from "@/components/ReDialog";
// import editForm from "./form.vue";
import { message } from "@/utils/message";
import dayjs from "dayjs";
// import { usePublicHooks } from "@/views/system/hooks";
interface FormItemProps {
  id?: string;
  region?: string;
  type?: string;
  area?: string;
  time?: string;
  violation?: string;
  description?: string;
  status?: string;
  date?: string;
  officer?: string;
}

export function usePaoSa() {
  const title = "垃圾收集点管理";

  const formModel = ref<FormItemProps>({
    status: "0"
  });
  const date = dayjs(new Date()).format("YYYY-MM-DD");
  const columns: TableColumnList = [
    { prop: "垃圾收集点", label: "垃圾收集点" },
    { prop: "收集点名称", label: "收集点名称" },
    { prop: "收集点位置描述", label: "收集点位置描述" },
    { prop: "收集点类型", label: "收集点类型" },
    { prop: "负责单位", label: "负责单位" },
    { prop: "总容量", label: "总容量" },
    { prop: "状态", label: "状态" },
    { prop: "操作", label: "操作", slot: "operation" }
  ];
  const addIcon = useRenderIcon(AddFill);
  const editIcon = useRenderIcon(EditPen);
  const delIcon = useRenderIcon(Delete);
  // // const { tagDisableStyle } = usePublicHooks();
  const rules: any[] = [
    {
      垃圾收集点: "001",
      收集点名称: "东城街道收集点",
      收集点位置描述: "东城街道中心公园旁",
      收集点类型: "社区",
      负责单位: "东城街道办",
      总容量: "50立方米",
      状态: "正常"
    },
    {
      垃圾收集点: "002",
      收集点名称: "西城街道收集点",
      收集点位置描述: "西城街道商业区",
      收集点类型: "商业",
      负责单位: "西城街道办",
      总容量: "30立方米",
      状态: "满"
    },
    {
      垃圾收集点: "003",
      收集点名称: "南城街道收集点",
      收集点位置描述: "南城街道菜市场",
      收集点类型: "市场",
      负责单位: "南城街道办",
      总容量: "40立方米",
      状态: "正常"
    },
    {
      垃圾收集点: "004",
      收集点名称: "北城街道收集点",
      收集点位置描述: "北城街道居民区",
      收集点类型: "居民区",
      负责单位: "北城街道办",
      总容量: "60立方米",
      状态: "正常"
    },
    {
      垃圾收集点: "005",
      收集点名称: "中城街道收集点",
      收集点位置描述: "中城街道文化广场",
      收集点类型: "公共",
      负责单位: "中城街道办",
      总容量: "70立方米",
      状态: "维护中"
    },
    {
      垃圾收集点: "006",
      收集点名称: "工业区收集点",
      收集点位置描述: "工业区入口处",
      收集点类型: "工业",
      负责单位: "工业区管理办",
      总容量: "80立方米",
      状态: "正常"
    },
    {
      垃圾收集点: "007",
      收集点名称: "科技园区收集点",
      收集点位置描述: "科技园区研发中心",
      收集点类型: "科技",
      负责单位: "科技园区管理办",
      总容量: "90立方米",
      状态: "满"
    },
    {
      垃圾收集点: "008",
      收集点名称: "教育区收集点",
      收集点位置描述: "教育区大学城",
      收集点类型: "教育",
      负责单位: "教育区管理办",
      总容量: "100立方米",
      状态: "正常"
    },
    {
      垃圾收集点: "009",
      收集点名称: "医疗区收集点",
      收集点位置描述: "医疗区医院旁",
      收集点类型: "医疗",
      负责单位: "医疗区管理办",
      总容量: "110立方米",
      状态: "正常"
    },
    {
      垃圾收集点: "010",
      收集点名称: "旅游区收集点",
      收集点位置描述: "旅游区风景区",
      收集点类型: "旅游",
      负责单位: "旅游区管理办",
      总容量: "120立方米",
      状态: "正常"
    }
  ];
  const formRef = ref();
  const dataList = ref([]);
  const loading = ref(true);
  /** 分页配置 */
  const pagination = reactive<PaginationProps>({
    pageSize: 20,
    currentPage: 1,
    pageSizes: [20, 40, 60],
    total: 0,
    align: "right",
    background: true,
    size: "default"
  });

  /** 加载动画配置 */
  const loadingConfig = reactive<LoadingConfig>({
    text: "正在加载第一页...",
    viewBox: "-10, -10, 50, 50",
    spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    // svg: "",
    // background: rgba()
  });

  /** 撑满内容区自适应高度相关配置 */
  const adaptiveConfig: AdaptiveConfig = {
    /** 表格距离页面底部的偏移量，默认值为 `96` */
    offsetBottom: 110
    /** 是否固定表头，默认值为 `true`（如果不想固定表头，fixHeader设置为false并且表格要设置table-layout="auto"） */
    // fixHeader: true
    /** 页面 `resize` 时的防抖时间，默认值为 `60` ms */
    // timeout: 60
    /** 表头的 `z-index`，默认值为 `100` */
    // zIndex: 100
  };

  function onSizeChange(val) {
    console.log("onSizeChange", val);
  }

  function onCurrentChange(val) {
    loadingConfig.text = `正在加载第${val}页...`;
    loading.value = true;
    delay(600).then(() => {
      loading.value = false;
    });
  }

  async function onSearch(newItem?: any) {
    loading.value = true;
    dataList.value = newItem ? [newItem].concat(rules) : rules;
    pagination.total = dataList.value.length;
    setTimeout(() => {
      loading.value = false;
    }, 500);
  }

  const resetForm = formEl => {
    if (!formEl) return;
    formEl.resetFields();
    onSearch();
  };
  function handleDelete(row: any) {
    console.log(row, "row");

    message(`操作成功`, { type: "success" });
    onSearch();
  }

  onMounted(() => {
    onSearch();
  });
  return {
    title,
    formModel,
    columns,
    addIcon,
    editIcon,
    delIcon,
    resetForm,
    onSearch,
    loading,
    dataList,
    pagination,
    loadingConfig,
    adaptiveConfig,
    onSizeChange,
    onCurrentChange,
    handleDelete
  };
}
